﻿namespace LizardChess
open System
open System.Threading
open System.Linq

//Piece name options - only change on Promotion
//change this to a quicker enum
exception InvalidName
type enmName=
    |Pawn = 0
    |Bishop = 1
    |Knight = 2
    |Rook = 3
    |Queen = 4
    |King = 5
    |Null = 6
    
//fixed id for each of the 32 starting pieces
type enmID=
    |WhiteQueensRook = 0
    |WhiteQueensKnight = 1
    |WhiteQueensBishop = 2
    |WhiteQueen = 3
    |WhiteKing = 4
    |WhiteKingsBishop = 5
    |WhiteKingsKnight = 6
    |WhiteKingsRook = 7
    |WhitePawn1 = 8
    |WhitePawn2 = 9
    |WhitePawn3 = 10
    |WhitePawn4 = 11
    |WhitePawn5 = 12
    |WhitePawn6 = 13
    |WhitePawn7 = 14
    |WhitePawn8 = 15
    |BlackQueensRook = 16
    |BlackQueensKnight = 17
    |BlackQueensBishop = 18
    |BlackQueen = 19
    |BlackKing = 20
    |BlackKingsBishop = 21
    |BlackKingsKnight = 22
    |BlackKingsRook = 23
    |BlackPawn1 = 24
    |BlackPawn2 = 25
    |BlackPawn3 = 26
    |BlackPawn4 = 27
    |BlackPawn5 = 28
    |BlackPawn6 = 29
    |BlackPawn7 = 30
    |BlackPawn8 = 31
    |Null = 32
//types of moves
type oMoveName =
    |Standard
    |CastleQueenSide
    |CastleKingSide
    |PawnPromotionQueen
    |PawnPromotionRook
    |PawnPromotionKnight
    |PawnPromotionBishop
    |EnPassent
    |NullMove
//piece
type piece =
    {
        Name: enmName;
        SquareOrd: int;
        pcIsWhite: bool;
        LastMoveTurnNo: int;
        NoOfMoves: int;
        HasBeenPromoted: bool;
        ID: enmID;
    }
    
//move details
type move =
    {
        mvPiece: int;
        mvPcName: enmName;
        From: int;
        To: int;
        pieceCaptured: int;
        mvName: oMoveName;
        FiftyMoveDrawCounter: int;
        PGN: string;
        UCI: string;
    }
//posn - used for current position but also as analysis progresses
type posn =
    {
        Sqs:int list;
        Pcs:piece list;
        Trn:int;
        Bcas:bool;
        Wcas:bool;
        Mhst:move list;
        IsWhite:bool;
    }
    member p.canK = p.Pcs.[4].NoOfMoves=0 && p.Pcs.[7].NoOfMoves=0 && p.Pcs.[7].SquareOrd<> -1
    member p.canQ = p.Pcs.[4].NoOfMoves=0 && p.Pcs.[0].NoOfMoves=0 && p.Pcs.[0].SquareOrd<> -1
    member p.cank = p.Pcs.[20].NoOfMoves=0 && p.Pcs.[23].NoOfMoves=0 && p.Pcs.[23].SquareOrd<> -1
    member p.canq = p.Pcs.[20].NoOfMoves=0 && p.Pcs.[16].NoOfMoves=0 && p.Pcs.[16].SquareOrd<> -1
//storage of variations
type varn = {name:string;isw:bool;brchs:posn list}
//test - records of tests
type test = {mvl:move list;mv:move;vnname:string}
//tst - test options random
type tst = {num:int;skip:int}
//tstlin - test options linear
type tstlin = {numlin:int;skiplin:int}
//tstres - test result
type tstres = {vname:string;visw:bool;dte:DateTime;res:int}
//eng - record of engine settings
type eng = {engine:string;mindepth:int;maxdepth:int;log:bool;}
//enganl - record of engine analysis results
type enganl = {depth:int;scr:int;bestmv:string;resp:string;bmPGN:string;rmPGN:string;}
//engbm - record of engine best moves
type engbm = {bnum:int;bisw:bool;bPGN:string;bstr:string;bscr:int;}